package SuanfaFenxi;

public class HomeWork_1 {
    public static void main(String[] args) {
        baiJiBaiQian();
        findWord();
        points();
    }
    public static void baiJiBaiQian(){
        int man=20;//公鸡5块一只,最多20只
        int women=0;//母鸡3块一只,最多33只
        int kid = 0;//小鸡1块三只,凑数
        for (;man>=0;man--){
            women=0;
            for (;women<33;women++){
                kid = 100-man-women;
                if(kid%3!=0){
                    continue;
                }
                int money = man*5+women*3+kid/3;
                if(money>100){
                    break;
                }
                if(money!=100){
                    continue;
                }
                System.out.println("公鸡:"+man+"母鸡:"+women+"小鸡:"+kid);
            }
        }
    }
    public static void findWord(){
        String w1 = "w[0..n-1]";
        String w2 = "M[0..m-1]";
        for(int i = 0;i<w1.length();i++){
            for (int j = 0;j<w2.length();j++){
                if(w1.substring(i,i+1).equals(w2.substring(j,j+1))){
                    System.out.println(i);
                    return;
                }
            }
        }
    }
    public static void points(){
        int[][] set = new int[6][2];//6个点
        //随机形成6个点
        for(int i = 0 ;i<6;i++){
            for(int j = 0;j<2;j++){
                set[i][j] = (int)(Math.random()*100);
            }
        }
        String s = "";

        for(int[] a:set)
        {
            s+=" (";
            for(int b:a)
            {
                s+=b+",";
            }
            s = s.substring(0,s.length()-1);
            s+=") ";
        }
        System.out.println("数组一览:"+s);

        int[] min1 = new int[]{0};
        int[] min2= new int[]{0};
        double minLen=100000000;
        for(int i =0;i<6;i++){
            int x1 = set[i][0];
            int y1 = set[i][1];
            for(int j = i+1;j<6;j++){
                int x2 = set[j][0];
                int y2 = set[j][1];
                double len = Math.sqrt(Math.abs(Math.pow(x1-x2,2)+Math.pow(y1-y2,2)));
                if(len<minLen){
                    minLen=len;
                    min1 = new int[]{x1,y1};
                    min2 = new int[]{x2,y2};
                }
            }
        }
        System.out.println("点1:("+min1[0]+","+min1[1]+")"+"点2:("+min2[0]+","+min2[1]+")距离:"+minLen);
    }
}
